package com.atguigu.controller.product;


import com.atguigu.dto.product.ProductDto;
import com.atguigu.entity.product.Product;
import com.atguigu.service.product.ProductService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "产品管理")
@RestController
@RequestMapping("/product/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @Operation(summary = "新增")
    @PostMapping("submit")
    public Result submit(@RequestBody Product product) {
        productService.submit(product);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除")
    @GetMapping("/remove/{productId}")
    public Result remove(@PathVariable Long productId) {
        productService.remove(productId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody Product product) {
        productService.update(product);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "上下架")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        productService.updateStatus(id, status);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "审核")
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable Long id, @PathVariable Integer auditStatus) {
        productService.updateAuditStatus(id, auditStatus);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据商品id查询商品信息")
    @GetMapping("/detail/{productId}")
    public Result detail(@PathVariable Long productId) {
        Product product = productService.detail(productId);
        return Result.build(product, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "列表（条件分页查询）")
    @GetMapping("/page/{current}/{limit}")
    public Result page(@PathVariable Integer current, @PathVariable Integer limit, ProductDto productDto) {
        PageInfo<Product> productList = productService.getPage(current, limit, productDto);
        return Result.build(productList, ResultCodeEnum.SUCCESS);
    }

}
